// mu1.C -- music1 and the calibrated Z
void a(vector<TH1 *> &v, TObject *h){ v.push_back((TH1F *)h); }
void mu1(){
  TFile *f = new TFile(getenv("TMP1"));
  TTree *etf = (TTree *)f->Get("etf");
  vector<TH1 *> v;
  TH1 *h;

  TCanvas *c = new TCanvas("c", "Amplitude related info - ADCs and QDCs", 1680, 1050);
  c->Divide(3, 3);
  c->cd(1); etf->Draw("mu1v[0]:mu1v[1]>>h1(500, 0., 5000., 500, 0., 5000.)", "", "colz");
  f->GetObject("h1", h); h->SetTitle("MUSIC1: Ch0 vs Ch1");
  h->GetXaxis()->SetTitle("Ch0"); h->GetYaxis()->SetTitle("Ch1");
  c->cd(2); etf->Draw("mu1v[2]:mu1v[3]>>h2(500, 0., 5000., 500, 0., 5000.)", "", "colz");
  f->GetObject("h2", h); h->SetTitle("MUSIC1: Ch2 vs Ch3");
  h->GetXaxis()->SetTitle("Ch2"); h->GetYaxis()->SetTitle("Ch3");
  c->cd(3); etf->Draw("mu1>>h3(500, 0., 5.)");
  f->GetObject("h3", h); h->SetTitle("MUSIC1: (1+2+3+4)/1000.");
  c->cd(4); etf->Draw("mu1:tof2>>h4(500, 110., 180., 500, 0., 5.)", "tof2 > 0.", "colz");
  f->GetObject("h4", h); h->SetTitle("MUSIC1 vs tof2 (T1->TOFWall)");
  h->GetXaxis()->SetTitle("tof2 [ns]"); h->GetYaxis()->SetTitle("mu1 arb.");
  c->cd(5); etf->Draw("mu1:pdcTaDWire[0][1]>>h5(36, -90., 90., 500, 0., 5.)",
    "pdcTaDWire[0][1]!=-999.", "colz");
  f->GetObject("h5", h); h->SetTitle("MUSIC1 vs Hit Y (DCTaD0-Y)");
  h->GetXaxis()->SetTitle("DCTaD0 Y [mm]"); h->GetYaxis()->SetTitle("mu1 arb.");
  c->cd(6); etf->Draw("mu1:pdcTaDWire[0][0]>>h6(36, -90., 90., 500, 0., 5.)",
    "pdcTaDWire[0][1]!=-999.", "colz");
  f->GetObject("h6", h); h->SetTitle("MUSIC1 vs Hit X (DCTaD0-X)");
  h->GetXaxis()->SetTitle("DCTaD0 X [mm]"); h->GetYaxis()->SetTitle("mu1 arb.");
  c->cd(7); etf->Draw("z1>>h7(500, 0., 80.)", "z1>0.");
  c->cd(8); etf->Draw("z1:tofwB.q()>>h8(500, 0., 5000., 500, 0., 40.)",
    "z1>0.&&tofwB.fired()==4", "colz");
  f->GetObject("h8", h); h->SetTitle("z1 vs TOFWall-QDC");
  h->GetXaxis()->SetTitle("T1 QDC"); h->GetYaxis()->SetTitle("z1");

  // the calibration
  c->cd(9);
  etf->Draw("(sqrt(mu1*exp(0.00095*(pdcTaDWire[1][1]+40.)))+0.6*beta-0.1*beta*mu1)*27.9688-17.357:beta>>h9(1000, 0.6, 0.9, 1000, 10., 80.)", "pdcTaDWire[1][1]!=-999.&&beta>0.&&beta<1.", "colz");
  f->GetObject("h9", h); h->SetTitle("Z1 vs beta");
  h->GetXaxis()->SetTitle("beta"); h->GetYaxis()->SetTitle("Z1");

  c->Print("mu1.pdf");
} // end function amp
